package com.gxstnu.controller;


import com.gxstnu.common.Result;
import com.gxstnu.entity.Admin;
import com.gxstnu.entity.User;
import com.gxstnu.service.AdminService;
import com.gxstnu.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController//定义controller
public class WebController {

    // 表示这是一个 get请求的接口
    @GetMapping("/")//定义接口
    public String hello(){
        return "Hello";//接口的返回值
    }

    @Resource
    AdminService adminService;
    @PostMapping("/login")
    public Result login(@RequestBody Admin admin){
        Admin dbAdmin = adminService.login(admin);
        return Result.success(dbAdmin);
    }

    @Resource
    UserService userService;

    @PostMapping("/user/login")
    public Result userLogin(@RequestBody User user){
        User dbUser = userService.login(user);
        return Result.success(dbUser);
    }
    @PostMapping("/user/register")
    public Result register(@RequestBody User user){
        userService.register(user);
        return Result.success();
    }


}
